﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstrumentCheck.Module;
using InstrumentCheck.BLL;

namespace InstrumentCheck.WebAppUI.UserControl
{
    public partial class UCSelectEmp : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            bool flag = false;
            if (txtCondition.Text.Trim() != "")
                flag = true;
            List<User> list = User_bll.GetQueryUser_bll(ddlCondition.SelectedItem.Value.ToString(),txtKeyWord.Text,flag);
            Session["listUser"] = list;
            BindGridView(list);
        }

        private void BindGridView(List<User> list)
        {
            gvUser.DataSource = list;
            gvUser.DataBind();
            gvUser.Visible = true;

            if (list == null)
            {
                gvUser.Visible = false;
                lblNoData.Text = "沒有找到任何資料！";
            }
            else
            {
                gvUser.Visible = true;
                lblNoData.Text = "";
            }
        }

        protected void gvUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List<User> list = Session["listUser"] as List<User>;
            gvUser.PageIndex = e.NewPageIndex;
            BindGridView(list);
        }

        protected void gvUser_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string str = PublicFunction.Decode(e.Row.Cells[0].Text) + "','" + PublicFunction.Decode(e.Row.Cells[1].Text) + "','";
                str += PublicFunction.Decode(e.Row.Cells[2].Text) + "','" + PublicFunction.Decode(e.Row.Cells[3].Text) + "','";
                str += PublicFunction.Decode(e.Row.Cells[4].Text);

                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E0E0E0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                e.Row.Attributes["style"] = "Cursor:hand";
                e.Row.Attributes.Add("OnClick", "returnUserValue('" + str + "')");
            }
        }
    }
}